<?php
class Voyage extends CI_Model {
    
    public $id;
    public $libelle;
    public $description;
    public $id_ville;
    public $id_type_voyage;
    
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    function getVoyages($limit,$page)
    {
        if($page==1){$page=0;}
        $query = $this->db->query("select * from voyage LIMIT $limit OFFSET $page");
        return $query->result("Voyage");
    }
    
    function getPhoto()
    {
        $query = $this->db->query('SELECT lien from photo where id_voyage='.($this->id));
        if ($query->num_rows() > 0)
        {
            return $query->first_row()->lien;
        }else{
           return null;
        }
    }
    
    function count()
    {
        $query = $this->db->query('SELECT count(id) as nb from voyage');
        if ($query->num_rows() > 0)
        {
            $res= $query->result();
            return $res[0]->nb;
        }else{
           return 0;
        }
    }
}
?>